package com.aerozhonghuan.logisticsmall.modules.order.logic;

import android.content.Context;

import com.aerozhonghuan.logisticsmall.framework.base.URLs;
import com.aerozhonghuan.logisticsmall.modules.order.beans.OrderDetailBean;
import com.aerozhonghuan.logisticsmall.modules.order.beans.OrderSettlementListBean;
import com.aerozhonghuan.logisticsmall.modules.order.beans.OrdersListBean;
import com.aerozhonghuan.logisticsmall.modules.order.beans.StoreBean;
import com.aerozhonghuan.logisticsmall.modules.order.beans.SubmitOrderInfo;
import com.aerozhonghuan.logisticsmall.widget.ProgressDialogIndicator;
import com.aerozhonghuan.oknet2.CommonCallback;
import com.aerozhonghuan.oknet2.RequestBuilder;
import com.google.gson.reflect.TypeToken;

/**
 * 描述
 *
 * @author zhangyonghui
 * 创建日期 2019-05-24
 */
public class OrderWebRequest {
    /**
     * 我的订单列表
     *
     * @param context
     * @param callback
     */
    public static void queryMyOrderList(Context context, int pageNumber, int status, CommonCallback<OrdersListBean> callback) {
        callback.setResponseType(new TypeToken<OrdersListBean>() {
        });
        RequestBuilder.with(context)
                .URL(URLs.SERVER_ORDER_LIST)
                .para("status", status)
                .para("pageSize", "20")
                .para("pageNumber", pageNumber)
                .onSuccess(callback).excute();
    }

    /**
     * 订单详情
     *
     * @param context
     * @param callback
     */
    public static void queryOrderDetail(Context context, ProgressDialogIndicator dialog, String billId, CommonCallback<OrderDetailBean> callback) {
        callback.setResponseType(new TypeToken<OrderDetailBean>() {
        });
        RequestBuilder.with(context)
                .URL(URLs.SERVER_ORDER_DETAIL)
                .progress(dialog)
                .para("billId", billId)
                .onSuccess(callback).excute();
    }

    /**
     * 取消订单
     *
     * @param context
     * @param callback
     */
    public static void cancelOrder(Context context, ProgressDialogIndicator dialog, String billId, CommonCallback<String> callback) {
        RequestBuilder.with(context)
                .URL(URLs.SERVER_ORDER_CANCEL)
                .progress(dialog)
                .para("billId", billId)
                .onSuccess(callback).excute();
    }

    /**
     * 确认服务
     *
     * @param context
     * @param callback
     */
    public static void confirmService(Context context, ProgressDialogIndicator dialog, String billId, CommonCallback<String> callback) {
        RequestBuilder.with(context)
                .URL(URLs.SERVER_ORDER_SERVICEOK)
                .progress(dialog)
                .para("billId", billId)
                .onSuccess(callback).excute();
    }

    /**
     * 我的结算
     *
     * @param context
     * @param callback
     */
    public static void querySettlements(Context context, int pageNumber, int status, CommonCallback<OrderSettlementListBean> callback) {
        callback.setResponseType(new TypeToken<OrderSettlementListBean>() {
        });
        RequestBuilder.with(context)
                .URL(URLs.SERVER_ORDER_SETTLEMENT)
                .para("status", status)
                .para("pageSize", "10")
                .para("pageNumber", pageNumber)
                .onSuccess(callback).excute();
    }

    /**
     * 请求所有的网点信息
     */
    public static void storesInfoRequest(String lat, String lng, Context context,
                                         ProgressDialogIndicator dialog, CommonCallback<StoreBean> callback) {
        TypeToken<StoreBean> type = new TypeToken<StoreBean>() {
        };
        callback.setResponseType(type);
        RequestBuilder.with(context)
                .URL(URLs.STORE_INFO_REQUEST)
                .progress(dialog)
                .para("lat", lat)
                .para("lng", lng)
                .onSuccess(callback).excute();
    }

    /**
     * 提交代付申请
     */
    public static void submitOrder(String billId, int stationId, Context context,
                                   ProgressDialogIndicator dialog, CommonCallback<SubmitOrderInfo> callback) {
        TypeToken<SubmitOrderInfo> type = new TypeToken<SubmitOrderInfo>() {
        };
        callback.setResponseType(type);
        RequestBuilder.with(context)
                .URL(URLs.SUBMIT_ORDER)
                .progress(dialog)
                .para("billId", billId)
                .para("stationId", stationId)
                .onSuccess(callback).excute();
    }
}
